import { $get, $delete, $put } from '@js/request'
import { WorkPerformanceSchema } from '@src/components/schema/performanceSchema'
export interface DataSchema {
  orderno?: number
  'id': string
  'caseid': string
  'caseno_desc': string
  'remark': string
  'score': number
  'performanceid': string
  'accountid': string
  'name': string
  'create_datetime': number
  'status': number
  'operator': string
  'operatorid': string
}

// 获取项
export async function getListRequest (work: WorkPerformanceSchema, performanceid: string): Promise<DataSchema[]> {
  const res = await $get('/api/commission/case_dismissal', {
    performanceid,
    condition: JSON.stringify([{ k: 'accountid', o: '=', v: work.accountid }])
  })
  res.data.forEach((li: DataSchema, i: number) => {
    li.orderno = i + 1
  })
  return res.data
}

export async function delRequest (id: string): Promise<void> {
  const res = await $delete(`/api/commission/case_dismissal/${id}`)
  return res.data
}

export interface OtherSchema {
  accepter_advise_count: number
  accepter_case_coefficient: string
}

// 获取咨询次数等信息
export async function getOtherInfoRequest (performanceid: string, accountid: string): Promise<OtherSchema> {
  const res = await $get('/api/commission/performance_score/getByperformanceid', {
    performanceid,
    accountid
  })
  return res.data
}

// 更新总体工作表现数据
export async function updateGradeRequest (performanceid: string, accountid: string, grade: string): Promise<void> {
  const res = await $put('/api/commission/performance_score/updateByperformanceid', {
    performanceid,
    accountid,
    accepter_case_coefficient: grade
  })
  return res.data
}
